
//懒加载 
const Home =()=>import('@/pages/Home')
const Search=()=>import('@/pages/search')
const Login =()=>import('@/pages/Login')
const Register=()=>import('@/pages/Register')
const Detail=()=>import('@/pages/Detail')
const AddCartSuccess=()=>import('@/pages/AddCartSuccess')
const ShopCart =()=>import('@/pages/ShopCart')
const Trade =()=>import('@/pages/Trade')
const Pay=()=>import('@/pages/Pay')
const PaySuccess =()=>import('@/pages/PaySuccess')
const Center =()=>import('@/pages/Center')


//二级路由
const MyOrder =()=>import('@/pages/Center/MyOrder')
const GroupOrder=()=>import('@/pages/Center/GroupOrder')

//路由配置信息
export default 
  [
    //重定向：在我们的项目运行起来，访问到/时，转到home
    {
      path:'/',
      redirect:'/home',
   
    }
    ,
    {
      path:'/home',
      component:Home,
      meta:{show:true}
    },
    {
      path:'/search/:keyword?',
      component:Search,
      meta:{show:true},
      name:'search',
      //路由组件能不能传递props数据？ 
      //布尔值写法
      // props:true
      
      //对象写法：额外的给路由组件传递一些props
      //props：{a:1,b:2}
      
      //函数写法：可以以params参数、query参数，通过props传递给路由组件
      props:($route)=>{
        return {keyWord:$route.params.keyWord,k:$route.query.k}
      }
    },
    {
      path:'/login',
      component:Login,
      meta:{show:false}
    },
    {
      path:'/register',
      component:Register,
      meta:{show:false}
    },
    {
      path:'/detail/:skuid',
      component:Detail,
      meta:{show:true}
    },
    {
     
      path:'/addcartsuccess',
      component:AddCartSuccess,
      meta:{show:true}
    },{
      path:'/shopcart',
      component:ShopCart,
      meta:{show:false}
    },{
      path:'/trade',
      component:Trade,
      meta:{show:false},
      beforeEnter:(to,from,next)=>{
        if(from.path=='/shopcart'){
         
          next()
        }else{
          next(false)
        }
      }
    },{
      path:'/pay',
      component:Pay,
      meta:{show:true},
      beforeEnter:(to,from,next)=>{
        if(from.path==('/trade')){
          next()
        }
        else{
          next(false)
        }
      }
    },{
      path:'/paysuccess',
      component:PaySuccess,
      meta:{show:true},
      beforeEnter:(to,from,next)=>{
        if(from.path=='/pay'){
          next()
        }else{
          next(false)
        }
      }
    },{
      path:'/center',
      component:Center,
      meta:{show:true},
      children:[
        {
          path:'myorder',//二级路由可以省略/
          component:MyOrder,
        },
        {
          path:'grouporder',
          component:GroupOrder
        }
        ,
        {
          path:'/center',
          redirect:'/center/myorder'
        }
      ]    
      
    }
   ]
  